<?php

namespace App\Models;

use DB;
use Illuminate\Database\Eloquent\Model;

class Scene extends Model
{
    public $timestamps = false;
    protected $guarded = [];

    public function area()
    {
        return $this->belongsTo('App\Models\Area');
    }

    public function type()
    {
        return $this->belongsTo('App\Models\Type');
    }

    public function monitors()
    {
        return $this->hasMany('App\Models\Monitor');
    }
    public function sceneInfo()
    {
        return $this->hasOne('App\Models\SceneInfo');
    }

    public static function groupWithCount($field='type_id'){
        $data = self::select([$field,DB::raw('Count('.$field.') as count')])->groupBy($field)->get();
        return $data;
    }
}
